package com.livesource.client;

import com.google.gwt.user.client.ui.VerticalPanel;
import com.livesource.client.model.entry.ProjectClass;
import com.livesource.client.model.project.Project;
import com.livesource.client.web.LiveSourcePage;
import com.livesource.client.web.sourceCode.FeatureDescription;
import com.livesource.client.web.sourceCode.filesTree.SourceFilesFiltersList;
import com.livesource.client.web.sourceCode.filesTree.SourceFilesList;
import com.livesource.client.webservices.LoadProjectFiles;

public class InitializeLiveSource {

	public static VerticalPanel vpLiveSource = new VerticalPanel();

	public static VerticalPanel getPanel(String userID,
			String projectSelectedID, String projectRepositoryType,
			String projectRepositoryURL) {

		LiveSourceGlobalVariables.currentUserID = userID;

		vpLiveSource.clear();

		vpLiveSource.add(new LiveSourcePage(
				SourceFilesFiltersList.VIEW_CLASS_FILES));

		if (LiveSourceGlobalVariables.currentProject == null
				|| !projectSelectedID
						.equals(LiveSourceGlobalVariables.currentProject
								.getProjectID())) {

			LiveSourceGlobalVariables.projectEntries = null;

			Project project = new Project(projectSelectedID,
					projectRepositoryType, projectRepositoryURL);

			LiveSourceGlobalVariables.currentProject = project;

			new LoadProjectFiles();

		} else {

			loadPanel();
		}

		return vpLiveSource;
	}

	public static void loadPanel() {

		SourceFilesList tree = new SourceFilesList(
				SourceFilesFiltersList.VIEW_CLASS_FILES,
				LiveSourceGlobalVariables.projectEntries);

		LiveSourcePage.featuresTreePanel.clear();
		LiveSourcePage.featuresTreePanel.add(tree);
	}

	public static void loadFeature(ProjectClass entry) {

		loadPanel();

		LiveSourcePage.featureVisualizationPanel.add(new FeatureDescription(
				entry));
	}

}
